package me.myset;

import java.util.Iterator;
import java.util.TreeSet;
import java.util.function.Consumer;

public class A01_TreeSetDemo1 {
    public static void main(String[] args) {
        //利用TreeSet存储整数并进行排序
        TreeSet<Integer> ts = new TreeSet<>();

        ts.add(5);
        ts.add(3);
        ts.add(1);
        ts.add(4);
        ts.add(2);

        //System.out.println(ts);

        //遍历集合（三种遍历方式）
        //1.迭代器
        Iterator<Integer> it = ts.iterator();
        while (it.hasNext()) {
            int next = it.next();
            System.out.println(next);
        }

        System.out.println("---------------------");

        //2.增强for
        for (int t : ts) {
            System.out.println(t);
        }

        System.out.println("----------------------");

        //.lambda表达式
        ts.forEach(i -> System.out.println(i));
    }
}
